Return-Path:
X-Original-To: apmail-commons-commits-archive@minotaur.apache.org
Delivered-To: apmail-commons-commits-archive@minotaur.apache.org
Received: from mail.apache.org (hermes.apache.org [140.211.11.3])
by minotaur.apache.org (Postfix) with SMTP id C5A391035E
for ;
Tue, 2 Dec 2014 21:20:28 +0000 (UTC)
Received: (qmail 26129 invoked by uid 500); 2 Dec 2014 21:20:27 -0000
Delivered-To: apmail-commons-commits-archive@commons.apache.org
Received: (qmail 25840 invoked by uid 500); 2 Dec 2014 21:20:27 -0000
Mailing-List: contact commits-help@commons.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@commons.apache.org
Delivered-To: mailing list commits@commons.apache.org
Received: (qmail 25562 invoked by uid 99); 2 Dec 2014 21:20:27 -0000
Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org)
(140.211.11.114)
by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Dec 2014 21:20:27 +0000
Received: by tyr.zones.apache.org (Postfix, from userid 65534)
id 495BA9BC21F; Tue, 2 Dec 2014 21:20:27 +0000 (UTC)
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
From: luc@apache.org
To: commits@commons.apache.org
Date: Tue, 02 Dec 2014 21:20:31 -0000
Message-Id:
In-Reply-To:
References:
X-Mailer: ASF-Git Admin Mailer
Subject: [5/8] [math] set up a weak link between a line and its reverse to
avoid duplications.
set up a weak link between a line and its reverse to avoid duplications.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/84cf29ec
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/84cf29ec
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/84cf29ec
Branch: refs/heads/master
Commit: 84cf29ecf31c67c7640f8821d4fdda625a173aa6
Parents: 6525cc4
Author: Luc Maisonobe
Authored: Tue Dec 2 15:37:15 2014 +0100
Committer: Luc Maisonobe
Committed: Tue Dec 2 15:37:15 2014 +0100
----------------------------------------------------------------------
.../math3/geometry/euclidean/twod/Line.java | 39 ++++++++++++++++++--
1 file changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/84cf29ec/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java
index b40f0fa..d6fd487 100644
--- a/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java
+++ b/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/Line.java
@@ -80,6 +80,9 @@ public class Line implements Hyperplane, EmbeddingThe line is oriented from p1 to p2
* @param p1 first point
@@ -118,6 +121,7 @@ public class Line implements Hyperplane, Embedding, Embedding, Embedding, Embedding, Embedding, EmbeddingGet a line with reversed orientation with respect to the
- * instance. A new object is built, the instance is untouched.
+ * instance.
+ *
+ * As long as neither the instance nor its reverse are modified
+ * (i.e. as long as none of the {@link #reset(Vector2D, Vector2D)},
+ * {@link #reset(Vector2D, double)}, {@link #revertSelf()},
+ * {@link #setAngle(double)} or {@link #setOriginOffset(double)}
+ * methods are called), then the line and its reverse remain linked
+ * together so that {@code line.getReverse().getReverse() == line}.
+ * When one of the line is modified, the link is deleted as both
+ * instance becomes independent.
+ *
* @return a new line, with orientation opposite to the instance orientation
*/
public Line getReverse() {
- return new Line((angle < FastMath.PI) ? (angle + FastMath.PI) : (angle - FastMath.PI),
- -cos, -sin, -originOffset, tolerance);
+ if (reverse == null) {
+ reverse = new Line((angle < FastMath.PI) ? (angle + FastMath.PI) : (angle - FastMath.PI),
+ -cos, -sin, -originOffset, tolerance);
+ reverse.reverse = this;
+ }
+ return reverse;
}
/** Transform a space point into a sub-space point.
@@ -383,6 +414,7 @@ public class Line implements Hyperplane, Embedding, Embedding