@@ -70,16 +70,20 @@ public Envelope(Envelope2D env2D) {
7070 public Envelope (VertexDescription vd ) {
7171 if (vd == null )
7272 throw new IllegalArgumentException ();
73+
7374 m_description = vd ;
7475 m_envelope .setEmpty ();
76+ _ensureAttributes ();
7577 }
7678
7779 public Envelope (VertexDescription vd , Envelope2D env2D ) {
7880 if (vd == null )
7981 throw new IllegalArgumentException ();
82+
8083 m_description = vd ;
8184 m_envelope .setCoords (env2D );
8285 m_envelope .normalize ();
86+ _ensureAttributes ();
8387 }
8488
8589 /**
@@ -331,8 +335,8 @@ void _setFromPoint(Point centerPoint, double width, double height) {
331335 }
332336
333337 void _setFromPoint (Point centerPoint ) {
334- m_envelope . setCoords (centerPoint .m_attributes [ 0 ],
335- centerPoint .m_attributes [ 1 ] );
338+ mergeVertexDescription (centerPoint .getDescription ());
339+ m_envelope . setCoords ( centerPoint .getX (), centerPoint . getY () );
336340 VertexDescription pointVD = centerPoint .m_description ;
337341 for (int iattrib = 1 , nattrib = pointVD .getAttributeCount (); iattrib < nattrib ; iattrib ++) {
338342 int semantics = pointVD ._getSemanticsImpl (iattrib );
@@ -610,7 +614,6 @@ int getEndPointOffset(VertexDescription descr, int end_point) {
610614 throw new IllegalArgumentException ();
611615
612616 int attribute_index = m_description .getAttributeIndex (semantics );
613- _ensureAttributes ();
614617 if (attribute_index >= 0 ) {
615618 return m_attributes [getEndPointOffset (m_description , end_point )
616619 + m_description .getPointAttributeOffset_ (attribute_index )
@@ -645,7 +648,6 @@ void setAttributeAsDblImpl_(int end_point, int semantics, int ordinate,
645648 throw new IllegalArgumentException ();
646649
647650 addAttribute (semantics );
648- _ensureAttributes ();
649651 int attribute_index = m_description .getAttributeIndex (semantics );
650652 m_attributes [getEndPointOffset (m_description , end_point )
651653 + m_description .getPointAttributeOffset_ (attribute_index ) - 2
@@ -655,32 +657,17 @@ void setAttributeAsDblImpl_(int end_point, int semantics, int ordinate,
655657 void _ensureAttributes () {
656658 _touch ();
657659 if (m_attributes == null && m_description .getTotalComponentCount () > 2 ) {
658- m_attributes = new double [(m_description .getTotalComponentCount () - 2 ) * 2 ];
660+ int halfLength = m_description .getTotalComponentCount () - 2 ;
661+ m_attributes = new double [halfLength * 2 ];
659662 int offset0 = _getEndPointOffset (m_description , 0 );
660663 int offset1 = _getEndPointOffset (m_description , 1 );
661-
662- int j = 0 ;
663- for (int i = 1 , n = m_description .getAttributeCount (); i < n ; i ++) {
664- int semantics = m_description .getSemantics (i );
665- int nords = VertexDescription .getComponentCount (semantics );
666- double d = VertexDescription .getDefaultValue (semantics );
667- for (int ord = 0 ; ord < nords ; ord ++)
668- {
669- m_attributes [offset0 + j ] = d ;
670- m_attributes [offset1 + j ] = d ;
671- j ++;
672- }
673- }
664+ System .arraycopy (m_description ._getDefaultPointAttributes (), 2 , m_attributes , offset0 , halfLength );
665+ System .arraycopy (m_description ._getDefaultPointAttributes (), 2 , m_attributes , offset1 , halfLength );
674666 }
675667 }
676668
677669 @ Override
678670 protected void _assignVertexDescriptionImpl (VertexDescription newDescription ) {
679- if (m_attributes == null ) {
680- m_description = newDescription ;
681- return ;
682- }
683-
684671 if (newDescription .getTotalComponentCount () > 2 ) {
685672 int [] mapping = VertexDescriptionDesignerImpl .mapAttributes (newDescription , m_description );
686673
@@ -734,8 +721,6 @@ protected void _assignVertexDescriptionImpl(VertexDescription newDescription) {
734721 throw new GeometryException (
735722 "This operation was performed on an Empty Geometry." );
736723
737- // _ASSERT(endPoint == 0 || endPoint == 1);
738-
739724 if (semantics == Semantics .POSITION ) {
740725 if (endPoint != 0 ) {
741726 return ordinate != 0 ? m_envelope .ymax : m_envelope .xmax ;
@@ -750,7 +735,6 @@ protected void _assignVertexDescriptionImpl(VertexDescription newDescription) {
750735
751736 int attributeIndex = m_description .getAttributeIndex (semantics );
752737 if (attributeIndex >= 0 ) {
753- _ensureAttributes ();
754738 return m_attributes [_getEndPointOffset (m_description , endPoint )
755739 + m_description ._getPointAttributeOffset (attributeIndex )
756740 - 2 + ordinate ];
@@ -784,14 +768,10 @@ void _setAttributeAsDbl(int endPoint, int semantics, int ordinate,
784768 throw new IndexOutOfBoundsException ();
785769
786770 if (!hasAttribute (semantics )) {
787- if (VertexDescription .isDefaultValue (semantics , value ))
788- return ;
789-
790771 addAttribute (semantics );
791772 }
792773
793774 int attributeIndex = m_description .getAttributeIndex (semantics );
794- _ensureAttributes ();
795775 m_attributes [_getEndPointOffset (m_description , endPoint )
796776 + m_description ._getPointAttributeOffset (attributeIndex ) - 2
797777 + ordinate ] = value ;
@@ -1015,7 +995,7 @@ public boolean equals(Object _other) {
1015995 return false ;
1016996
1017997 for (int i = 0 , n = (m_description .getTotalComponentCount () - 2 ) * 2 ; i < n ; i ++)
1018- if (m_attributes [i ] != other .m_attributes [i ])
998+ if (! NumberUtils . isEqualNonIEEE ( m_attributes [i ], other .m_attributes [i ]) )
1019999 return false ;
10201000
10211001 return true ;
@@ -1030,7 +1010,7 @@ public boolean equals(Object _other) {
10301010 public int hashCode () {
10311011 int hashCode = m_description .hashCode ();
10321012 hashCode = NumberUtils .hash (hashCode , m_envelope .hashCode ());
1033- if (!isEmpty () && m_attributes != null ) {
1013+ if (!isEmpty ()) {
10341014 for (int i = 0 , n = (m_description .getTotalComponentCount () - 2 ) * 2 ; i < n ; i ++) {
10351015 hashCode = NumberUtils .hash (hashCode , m_attributes [i ]);
10361016 }
0 commit comments